import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import './style.scss'
//引入工具
import Message from './utils/Message'
import Request from '@/utils/Request'
import Utils from '@/utils/Utils'
//引入eps
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//引入cookies
import VueCookies from 'vue-cookies'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// 或
router.afterEach(() => {
  const parent = document.querySelector(`.main-container`)
//scrollTo可以直接传入滚动的X,Y值，也可以传入一个对象
//直接传值
  parent.scrollTo(0,0)
});
app.use(router)
app.use(ElementPlus)
app.config.globalProperties.VueCookies = VueCookies;
app.config.globalProperties.Message = Message;
app.config.globalProperties.Request = Request;
app.config.globalProperties.Utils = Utils;
// 问题：刷新后全局属性值要丢失，
// 需求：1.全局基本都要用
// 
// 找到所有分类的方法更新到全局
// const getCategory = async ()=>{
//   let result = await Request({
//       url:"/workCaseCategory/loadDataList",
//       params: {},
//       showLoading:false
//   })
//   if(!result){
//     return;
//   }else{
//     app.config.globalProperties.CategoryList = result.data.list;
//   }
// }
// getCategory();
// app.config.globalProperties.UpDateCategory = getCategory;
//找到所有的作品更新到全局
const getWorkCaseList = async ()=>{
  let result = await Request({
          url:"/workCase/loadDataList",
          params:{
              pageNo:1,
              pageSize:10000
          },
          showLoading:false
      })
  if(!result){
      return;
  }else{
    app.config.globalProperties.WorkCaseList = result.data.list;
  }
}
getWorkCaseList();
app.config.globalProperties.UpDateWorkCaseList = getWorkCaseList;
// 解决Vue中的全局变量和函数报错问题
declare module 'vue' {
export interface ComponentCustomProperties {
  VueCookies,
  Message,
  Request,
  Utils,
  CategoryList,
  UpDateCategory,
  WorkCaseList,
  UpDateWorkCaseList
}
}
app.mount('#app')
